package books4africa



import grails.test.mixin.*
import org.junit.*

@TestFor(Book)
class BookTests {

    void testBook() { 
				
    	Book bookTest = new Book(title: null, author: "Author", description: null, edition: null, publishDate: null, isbn: 0, minGrade: 2, maxGrade: 5, category: "Math");		
		//test: book doesn't have a title
		assertFalse(bookTest.validate());
		
		bookTest.title = "Title";
		bookTest.author = null;
		
		//test: book doesn't have an author
		assertFalse(bookTest.validate());
		
		bookTest.author = "Author";
		bookTest.minGrade = -1;
		
		//test: book doesn't have a minimum grade level
		assertFalse(bookTest.validate());
		
		bookTest.minGrade = 2;
		bookTest.maxGrade = 7;
		
		//test: book doesn't have a maximum grade level
		assertFalse(bookTest.validate());
		
		bookTest.maxGrade = 5;
		
        
                Book goodBook = new Book(title: "Title", author: "Author", description: null, edition: null, publishDate: null, isbn: 0, minGrade: 2, maxGrade: 5, category: "Math")
                
                 
  
		//test: book has all required fields filled out correctly
		assertTrue(goodBook.validate());
    }
}
